package org.example;

// 测试『固定上边界通配符』

class Holder<T> {
    private T value;

    public Holder(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }
}
public class UpperBoundedWildcardsTests {

    public static void add10(Holder<Number> numberHolder){
        System.out.println("加10之后的值：" + (numberHolder.getValue().longValue() + 10));
    }

    public static void add100(Holder<? extends Number> numberHolder){
        System.out.println("加100之后的值：" + (numberHolder.getValue().longValue() + 100));
    }


    public static void main(String[] args) {
        // 编译错误：java: incompatible types: org.example.Holder<java.lang.Integer> cannot be converted to org.example.Holder<java.lang.Number>
        // add10(new Holder<Integer>(10));

        add100(new Holder<Integer>(10));
        add100(new Holder<Long>(10000L));
    }
}